﻿@using Hiwjcn.Core.Domain.Auth;
@{
    this.SetLayout("AuthManageLayout");
    this.SetTitle("用户");
}

<div class="row">
    <div class="col-md-12">
        <div class="box_con">
            <form action="/AuthManage/Users" method="get">
                <div class="input-group">
                    <input type="text" class="form-control" name="q" value="@(ViewData["q"])" placeholder="搜索用户..." />
                    <span class="input-group-btn">
                        <button class="btn btn-primary" type="submit">搜索</button>
                    </span>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="panel panel-default">
    <div class="panel-heading">
        <span class="fa fa-user"></span>
        <span>用户</span>
    </div>
    <div class="panel-body">
        @{
            var list = this.GetNotNullViewData<List<LoginUserInfo>>("list");
            if (ValidateHelper.IsPlumpList(list))
            {
                <table class="table table-striped table-hover">
                    <thead>
                        <tr>
                            <td>用户名</td>
                            <td>详细数据</td>
                            <td></td>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var m in list)
                        {
                            <tr>
                                <td>@(m.UserNameOrNickName())</td>
                                <td style="width:400px;word-break:break-all;">
                                    @if (m.ExtraData != null)
                                    {
                                        <span>@(m.ExtraData.ToJson())</span>
                                    }
                                </td>
                                <td>
                                    <button class="btn btn-link btn-sm del" data-id="@(m.UserID)">从所有端下线</button>
                                </td>
                            </tr>
                        }
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="5" class="right">
                                @(Pager())
                            </td>
                        </tr>
                    </tfoot>
                </table>
            }
            else
            {
                <div class="alert alert-info">没有找到用户</div>
            }
        }
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $('.del').click(function () {
            if (!confirm('确定强制下线此用户嘛？')) {
                return false;
            }

            var btn = $(this);
            var id = btn.data('id');

            postJson('/AuthManage/DeleteUserTokens', { user_uid: id }, function (res) {
                if (res && res.Success) {
                    alert('操作成功');
                    btn.fadeOut();
                    setTimeout(function () {
                        btn.fadeIn();
                    }, 1000 * 5);
                }
                else {
                    alert(res.ErrorMsg);
                }
            });

            return false;
        });
    });
</script>